/*
 * Fichier: JConsole.java
 * Crée le: 31 mars 2006.
 * Modifié: 14 février 2009.
 * Auteurs: Sébastien ESTIENNE.
 * SiteWeb: http://www.prog-info.org/
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package javaexos.gui.common;



import java.awt.Color;
import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;



/**
 * <p>Classe simulant une console.</p>
 * @author Sébastien ESTIENNE.
 */
public final class GConsole extends JFrame
{
   /**
    * <p>Serial version UID.</p>
    */
   private static final long serialVersionUID = 1L;

   /** L'instance statique. */
   private static GConsole instance;
   
   /** Zone de texte. */
   private JTextArea zoneTexte;


   /**
    * <p>Construit la console.</p>
    */
   private GConsole()
   {
      super("Console");

      // Initialisation de la zone de texte.
      this.zoneTexte = new JTextArea();
      this.zoneTexte.setForeground(Color.WHITE);
      this.zoneTexte.setBackground(Color.BLACK);
      this.zoneTexte.setFont(new Font("Monospaced", Font.PLAIN, 12));
      this.zoneTexte.setEditable(false);

      // Ajoute la zone de texte à la fenêtre.
      getContentPane().add(this.zoneTexte);

      // Propriétés de la fenêtre.
      setLocation(50, 50);
      setSize(500, 300);
      setResizable(true);
      setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
   }
   
   
   /**
    * <p>Récupère l'instance unique de la classe Log.<p>
    * @return Retourne l'instance unique de la classe Log.
    */
   public static GConsole getInstance()
   {
      if(instance == null)
      {
         instance = new GConsole();
      }

      return instance;
   }


   /**
    * <p>Affiche un message dans la console.</p>
    * @param text Le texte à afficher.
    */
   public void print(String text)
   {
      this.zoneTexte.append(text);
   }
   
   /**
    * <p>Efface tout le texte de la console.</p>
    */
   public void clear()
   {
      this.zoneTexte.setText("");
   }
}
